package de.zainodis.authorlist.core;

import de.zainodis.authorlist.model.AuthorLibraryComponent;
import de.zainodis.commons.component.Component;
import de.zainodis.commons.component.Entity;
import de.zainodis.commons.component.IEntity;

/**
 * We'll use this as our main entity to which we'll add components.
 * 
 * @author fzarrai
 * 
 */
public class Application extends android.app.Application {

   private static final IEntity rootEntity = new Entity();

   private static Application self;

   @Override
   public void onCreate() {
	 super.onCreate();
	 self = this;

	 // Add required components
	 rootEntity.addComponent(new AuthorLibraryComponent(rootEntity));
   }

   /**
    * @param requested
    *           the type of the component that should be returned.
    * @return a matching component (if it has been added); null otherwise.
    */
   public static <T extends Component> T getComponent(Class<T> requested) {
	 return rootEntity.getComponent(requested);
   }

   public static String getStringFromResId(int resId) {
	 return self.getString(resId);
   }
}
